package com.lt.bcra.controller.questionnaire;


import com.lt.bcra.entity.BcraDefaultValue;
import com.lt.bcra.exception.BaseException;
import com.lt.bcra.service.BcraDefaultValueService;
import com.lt.bcra.result.ResponseEnum;
import com.lt.bcra.result.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 问题默认值表 前端控制器
 * </p>
 *
 * @author LuoTian
 * @since 2022-05-25
 */
@Api(tags = "默认值查看表")
@CrossOrigin //跨域可以前端配置
@RestController
@RequestMapping("bcra/defaultValue")
public class BcraDefaultValueController {

    private static Logger log = LoggerFactory.getLogger(BcraDefaultValueController.class);

    @Autowired
    private BcraDefaultValueService bcraDefaultValueService;

    @GetMapping("/getDefaultValue")
    @ApiOperation("查看默认值配置表")
    public ResultData list() throws BaseException {
        if (log.isDebugEnabled()) log.debug("查看默认值配置表 BcraDefaultValueController");

        List<BcraDefaultValue> list = bcraDefaultValueService.list();
        if (list == null){
            throw new BaseException(ResponseEnum.SELECT_DATA_ERROR);
        }
        return ResultData.getResult(list);
    }
    @DeleteMapping("/deleteDefaultValue")
    @ApiOperation("删除默认值配置表")
    @ApiParam(value = "id")
    public ResultData delete(Integer id) throws BaseException{
        if (log.isDebugEnabled()) log.debug("删除默认值配置表 BcraDefaultValueController");

        boolean isRemove = bcraDefaultValueService.removeById(id);
        if (!isRemove){
            throw new BaseException(ResponseEnum.DELETE_DATA_ERROR);
        }
        return ResultData.getResult(isRemove);
    }
}

